home *** CD-ROM | disk | FTP | other *** search
/ Resource Library: Multimedia / Resource Library: Multimedia.iso / maestro / source / vcredit / vcrdtprt.c < prev    next >
Encoding:
Text File  |  1993-06-15  |  22.7 KB  |  641 lines

  1. /*
  2.  * Copyright (c) 1990, 1991, 1992 Stanford University
  3.  *
  4.  * Permission to use, copy, modify, and distribute this software and 
  5.  * its documentation for any purpose is hereby granted without fee, provided
  6.  * that (i) the above copyright notices and this permission notice appear in
  7.  * all copies of the software and related documentation, and (ii) the name
  8.  * Stanford may not be used in any advertising or publicity relating to
  9.  * the software without the specific, prior written permission of
  10.  * Stanford.
  11.  * 
  12.  * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, 
  13.  * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY 
  14.  * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  
  15.  *
  16.  * IN NO EVENT SHALL STANFORD BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
  17.  * INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES
  18.  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER OR NOT
  19.  * ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF LIABILITY,
  20.  * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  21.  * SOFTWARE.
  22.  */
  23.  
  24. /* $Header: /Source/Media/collab/vcrEdit/RCS/vcrEditProtocol.c,v 0.36 92/11/17 14:43:34 drapeau Exp $ */
  25. /* $Log:    vcrEditProtocol.c,v $
  26.  * Revision 0.36  92/11/17  14:43:34  drapeau
  27.  * Cleaned up code to better conform to ANSI-C specs.
  28.  * 
  29.  * Revision 0.35  92/09/29  18:10:43  drapeau
  30.  * Made slight modifications to PerformSelection(), mostly in the semantics used
  31.  * for the PlayEdit() function.  When calling PlayEdit(), the application now
  32.  * uses case C of the VideoObject's DevPlayFromTo semantics.  Case c states
  33.  * that start == 0 and end != 0, meaning that the device should begin
  34.  * playback from its current point and continue until the address "end"
  35.  * has been reached.  Using this case instead of case D (specifying both start
  36.  * and end addresses, causing an extra search) reduces delay time for most
  37.  * devices.
  38.  * Also, made cosmetic changes to enhance readability and ANSI compliance.
  39.  * 
  40.  * Revision 0.34  92/09/24  16:41:06  drapeau
  41.  * Made changes to the way the VideoObject methods were used.  Part of the
  42.  * reason for the changes is that the semantics of the VideoObject itself
  43.  * have been changed; part of the reason is that vcrEdit was using some
  44.  * bad semantics when using the PlayFromTo method.
  45.  * Also, made a number of cosmetic changes for better readability and
  46.  * ANSI compliance.
  47.  * 
  48.  * Revision 0.33  92/09/08  14:31:16  drapeau
  49.  * Replaced references to NTSC-specific frame rate with the newly-defined
  50.  * constant "FrameRate", which is set at compile time through a Makefile
  51.  * variable.
  52.  * 
  53.  * Revision 0.32  92/05/29  12:35:52  drapeau
  54.  * Modified code to track new name of the MAEstro "Selection" structure;
  55.  * it is now named "MAESelection".
  56.  * 
  57.  * Revision 0.31  92/05/14  00:08:49  drapeau
  58.  * A number of changes were made, the most significant having to do with the
  59.  * implementation of the pre-search mechanism.
  60.  * * Pre-search was flawed in that it assumed that playback always happened
  61.  *   right after authorship of a document (i.e., a document could not be played
  62.  *   repeatedly and still have pre-search work).  This error has been fixed,
  63.  *   by removing the "numOnTL" variable, which used to indicate how many
  64.  *   edits had been placed on the TimeLine (this was done by counting the
  65.  *   number of times that GetSelection() was called, but the number was
  66.  *   only saved during the time the application was open; the next launch
  67.  *   of vcrEdit would cause numOnTL to be reset).
  68.  * 
  69.  *   Also, removed the extraneous variable "nextTLSelection", the function
  70.  *   of which is just as well served by prudent use of the "editnum"
  71.  *   variable, which keeps track of the currently-selected edit.
  72.  * 
  73.  *   Also, the application no longer turns off pre-search when its guess
  74.  *   about the next edit to be played is incorrect.  In essense, pre-search
  75.  *   is like a cache.  vcrEdit used to turn off caching as soon as the first
  76.  *   cache miss occurred.  Now, the cache remains on, assuming that the
  77.  *   cache will succeed most of the time.  This assumption was made based
  78.  *   on real-world authors using vcrEdit over the past five months.
  79.  * 
  80.  *   Also, pre-search checks for the boundary condition when the last edit
  81.  *   has been played.  Pre-search is not turned off, but a flag is set
  82.  *   to indicate that the last edit on the current edit list was played,
  83.  *   so a real search must be done, no matter what edit is to be played
  84.  *   next.
  85.  * 
  86.  * * Made a number of formatting changes to the code to conform to
  87.  *   coding standards.
  88.  * * Made some changes to the code for better ANSI-C conformance.
  89.  * 
  90.  * Revision 0.30  92/01/09  18:18:46  drapeau
  91.  * Slight modifications to make code ANSI-compliant.
  92.  * 
  93.  * Revision 0.29  92/01/03  18:02:55  drapeau
  94.  * Changed all calls to Browse() to use "0" instead of "NULL", to
  95.  * take into account ANSI-C definition of NULL as (void*)0.
  96.  * 
  97.  * Revision 0.28  91/09/29  16:13:54  lim
  98.  * *** empty log message ***
  99.  * 
  100.  * Revision 0.27  91/09/26  12:46:11  lim
  101.  * *** empty log message ***
  102.  * 
  103.  * Revision 0.26  91/09/26  12:34:30  lim
  104.  * 1. Returns from protocol functions immediately if no driver
  105.  * is installed.
  106.  * 2. Corrected duration for GetSelection for the case when no
  107.  * driver is installed.
  108.  * 3. Did casting.
  109.  * 
  110.  * Revision 0.25  91/08/30  15:15:33  lim
  111.  * Don't send error message in InitNetwork.
  112.  * 
  113.  * Revision 0.24  91/08/28  12:58:29  lim
  114.  * Presearching is implemented.
  115.  * Set selection for the first edit is the same as before.
  116.  * In perform selection, a timer is set for the length of
  117.  * the edit. 
  118.  * When the timer expires, SetSelection is called for the
  119.  * next edit on the edit list. 
  120.  * When the TimeLine next calls SetSelection (when the playhead
  121.  * hits the next edit), if the presearched edit is the correct
  122.  * edit, SetSelection will return, allowing PerformSelection to
  123.  * be called almost immediately.
  124.  * If however, it is the wrong edit, then it is likely that the
  125.  * user is not using PreSearching as it was intended (for 
  126.  * edits on the TimeLine that are in the same sequence as in
  127.  * the edit list). In this case, PreSearching is automatically
  128.  * turned off, to prevent performance degradation from searching
  129.  * for the wrong edit.
  130.  * If PauseSelection is hit, the timer is killed, and so presearching
  131.  * will resume only after PerformSelection is called on the next
  132.  * edit.
  133.  *  The number of edits on the TimeLine is estimated by the number of
  134.  * times GetSelection is called. The exact number depends on how many
  135.  * edits are deleted. If the user only places 2 out of 5 edits in
  136.  * his edit list, then the application will not call search on the
  137.  * 3rd edit on the edit list. 
  138.  * 
  139.  * Revision 0.23  91/08/24  18:00:13  lim
  140.  * Implemented PrintDiagnostics. With command line flag '-d', the 
  141.  * app will launch such that it prints all diag messages.
  142.  * 
  143.  * Revision 0.22  91/08/23  17:24:32  lim
  144.  *  Document format has changed.
  145.  * 
  146.  * Revision 0.21  91/08/21  14:34:01  lim
  147.  * Implemented GetAppIcon().
  148.  * 
  149.  * Revision 0.20  91/08/20  16:32:29  lim
  150.  * Set Selection now blanks out screen after search and 
  151.  * Perform Selection will unblank it.
  152.  * 
  153.  * Revision 0.19  91/08/20  15:46:14  lim
  154.  * Get selection now returns a duration of -1 if no edit has been selected.
  155.  * 
  156.  * Revision 0.18  91/08/20  14:46:35  lim
  157.  * Corrected set selection offset.
  158.  * 
  159.  * Revision 0.17  91/08/20  10:01:56  lim
  160.  * HaltSelection() and PauseSelection() now directly call DevStop() and
  161.  * DevStill() instead of Stop() and Pause(). This is because Pause() is 
  162.  * implemented to toggle between Still() and Play() and that is not
  163.  * the behavior we want.
  164.  * 
  165.  * Revision 0.16  91/08/17  20:46:34  lim
  166.  * No longer have to worry about interruptibility. All stops and pauses
  167.  * have interrupt capability.
  168.  * OpenPanel now called Browse.
  169.  * 
  170.  * Revision 0.15  91/08/16  13:03:12  lim
  171.  * Always display 2-digit numbers for hr, sec, min, frame.
  172.  * 
  173.  * Revision 0.14  91/08/16  12:36:52  lim
  174.  * 1. editFilename gone. Read from title bar.
  175.  * 2. Call Browse() with OPENPANEL_CHECK for open doc.
  176.  * 3. Functions will check for validity of command before proceeding.
  177.  * 
  178.  * Revision 0.13  91/08/15  12:59:29  lim
  179.  * Changed FileLoad() call to OpenHandler() calls.
  180.  * 
  181.  * Revision 0.12  91/08/08  16:35:07  lim
  182.  * 1. Added instance pointer to each public videoObject function call.
  183.  * 2. speedStg is now an array of integers.
  184.  * 3. For PauseSelection() and HaltSelection(), interruptible is set 
  185.  *    appropriately so that either Pause() (Stop()) or DevClearMarker()
  186.  *    is called.
  187.  * 
  188.  * Revision 0.11  91/07/20  11:44:46  lim
  189.  * Replaced DevPlayFromTo calls with PlayEdit.
  190.  * Cleaned up code.
  191.  * 
  192.  * Revision 0.10  91/07/16  16:17:35  lim
  193.  * Initial revision.
  194.  *  */
  195.  
  196. #include <xview/notify.h>
  197. #include "vcrEdit.h"
  198.  
  199. char*        realpath(char*, char*);
  200. void        OpenDoc();
  201. void        SetSelection();
  202. void        PerformSelection();
  203. char**        GetDoc();
  204. MAESelection*    GetSelection();
  205. void        HaltSelection();
  206. void        PauseSelection();
  207. void        ResumeSelection();
  208. void        HideApplication();
  209. void        ShowApplication();
  210. IconData*    GetAppIcon();
  211.  
  212. static char *canonFilename;
  213. static char lprcsid[] = "$Header: /Source/Media/collab/vcrEdit/RCS/vcrEditProtocol.c,v 0.36 92/11/17 14:43:34 drapeau Exp $";
  214.  
  215. Sender*        sender;
  216. Receiver*    receiver;
  217. enum Boolean    preSearch = No;                        /* Flag : whether the device should presearch when */
  218. enum Boolean    lastEditPlayed = No;                    /* Flag : Reflects boundary condition when last... */
  219.                                     /* ...edit on the edit list was just played, but... */
  220.                                     /* ...pre-search is still on.  If the author wanted... */
  221.                                     /* ...to re-play the last edit, whatever function that... */
  222.                                     /* ...checks if presearch is set (SetSelection here)... */
  223.                                     /* ...should also check this flag.  If this flag is... */
  224.                                     /* ..."Yes", it is not possible to pre-search (i.e., the... */
  225.                                     /* ...last edit on the list was played).  If this... */
  226.                                     /* ...flag is "No", then there remain edits on the list... */
  227.                                     /* ...to be played, and so pre-search is still valid. */
  228.  
  229. void 
  230.   InitNetwork(char* h)
  231. {
  232.   Port senderPort;
  233.   char diagMsg[30];
  234.   
  235.   static  DispatchTable  DT = 
  236.   {
  237.     OpenDoc,
  238.     GetDoc,
  239.     GetSelection,
  240.     SetSelection,
  241.     PerformSelection,
  242.     NULL,
  243.     NULL,
  244.     NULL,
  245.     NULL,
  246.     NULL,
  247.     NULL,
  248.     HaltSelection,
  249.     PauseSelection,
  250.     ResumeSelection,
  251.     HideApplication,
  252.     ShowApplication,
  253.     GetAppIcon
  254.     };
  255.   
  256.   lines = 0;
  257.   clearframe = 0;
  258.   change = 0;
  259.   search = 0;
  260.   editnum = -1;
  261.   senderPort.hostName = h;                        /* Networking stuff */
  262.   senderPort.portNumber = PortMgrPortNumber;
  263.   sender = NewSender(&senderPort);
  264.   if (sender)
  265.   {    
  266.     receiver = NewReceiver(sender, "vcrEdit", receiverPort);
  267.     sprintf(diagMsg, "Listening on port %d.\n", receiver->transport->xp_port);
  268.     PrintDiagnostics(diagMsg);
  269.     
  270.     BuildDispatchTable (&DT);
  271.   }
  272.   canonFilename = (char *) malloc(MAX_PATHLENGTH);
  273.   (void) notify_enable_rpc_svc (TRUE);
  274. }                                    /* end function InitNetwork */
  275.  
  276.  
  277.  
  278. /* Open document as directed by TimeLine.
  279.  * Check that the current file is saved first.
  280.  */
  281. void OpenDoc(char** filename)
  282. {
  283.   int result;
  284.   char fullFilename[MAX_PATHLENGTH];
  285.   char* currentFile = (char*) xv_get(vcrEdit_editPopup->editPopup,
  286.                      XV_LABEL);
  287.   if (strcmp(*filename, "Untitled") != 0)                /* Check that filename is not 'Untitled' */
  288.   {
  289.     if (strlen(currentFile) == 0) strcpy (currentFile, ".");        /* If no filename specified in panel, set to '.' (directory) */
  290.     
  291.     if (realpath(currentFile, fullFilename) != NULL)
  292.       strcpy(fullFilename, (char*) realpath(currentFile, fullFilename));
  293.     else strcpy(fullFilename, ".");
  294.     if ((strcmp(fullFilename, *filename) != 0) &&            /* Check if filename given by the TimeLine is... */
  295.     (strcmp(currentFile, *filename) != 0))                /* ...the same as that on the panel textfield */
  296.     {
  297.       result = NOTICE_NO;                        /* Check if unsaved changes exist in edit list */
  298.       if ((change) && (lines > 0)) 
  299.     result = DisplayChoice("Unsaved changes exist in the video edit list.",
  300.                    "Loading a file will erase all changes. Go ahead and load the file?",
  301.                    "No", "Yes");    
  302.       if (result == NOTICE_NO)
  303.       {
  304.     change = 0;
  305.     Browse(*filename, BrowseCheckOpen, 0, "#VCR Edit Document#", "vcrEdit");
  306.       }
  307.     }
  308.   }  
  309. }                                    /* end function OpenDoc */
  310.  
  311.  
  312.  
  313. void SetSelection(MAESelection* selection)                /* Seek to selection as directed by TimeLine */
  314. {
  315.   char shr[2];
  316.   char smin[2];
  317.   char ssec[2];
  318.   char sframe[2];
  319.   char ehr[2];
  320.   char emin[2];
  321.   char esec[2];
  322.   char eframe[2];
  323.   char diagMsg[30];
  324.   char msg[30];
  325.   char audio[7];
  326.   int starthr, startmin, startsec, startfr, startAddress;
  327.   int endhr, endmin, endsec, endfr;
  328.   
  329.   if (!myVideo)                                /* If no video driver installed, return immediately */
  330.     return;
  331.   if ((preSearch == Yes) && (lastEditPlayed == No))            /* Was the pre-search option set, and is it safe... */
  332.   {                                    /* ...to do pre-search? */
  333.     if (editnum == selection->start - 1)                /* Presearch is completed. Ignore this SetSelection */
  334.       return;                                /* if it presearched to the correct edit */
  335.   }
  336.   lastEditPlayed = No;                            /* Reset flag saying that last edit hasn't been played */
  337.   if (selection->start > 0 && selection->start <= lines)       
  338.   {
  339.     sprintf(diagMsg, "In SetSelection, offset = %d ms\n",
  340.         selection->offset);
  341.     PrintDiagnostics(diagMsg);
  342.     if (editnum != -1)                            /* Deselect any current selection */
  343.       xv_set(vcrEdit_editPopup->editScrollList,
  344.          PANEL_LIST_SELECT, editnum, FALSE,
  345.          NULL);
  346.     editnum = selection->start - 1;
  347.     sscanf(startframe[editnum], "%d:%d:%d:%d",                /* Get original start */
  348.        &starthr, &startmin, &startsec, &startfr);
  349.     
  350.     startAddress = ConvertToAddress(starthr, startmin, startsec, startfr) + /* Add offset to start address */
  351.       (selection->offset) / 1000 * FrameRate;
  352.     ConvertToTime(&starthr, &startmin, &startsec, &startfr, startAddress);
  353.     sprintf(shr, "%.2d", starthr);
  354.     sprintf(smin, "%.2d", startmin);
  355.     sprintf(ssec, "%.2d", startsec);
  356.     sprintf(sframe, "%.2d", startfr);
  357.     
  358.     xv_set(vcrEdit_editPopup->editStartTxt1, PANEL_VALUE, shr, NULL); /* Load the appropriate values into the textfields */
  359.     xv_set(vcrEdit_editPopup->editStartTxt2, PANEL_VALUE, smin, NULL);
  360.     xv_set(vcrEdit_editPopup->editStartTxt3, PANEL_VALUE, ssec, NULL);
  361.     xv_set(vcrEdit_editPopup->editStartTxt4, PANEL_VALUE, sframe, NULL);
  362.     
  363.     sscanf(endframe[editnum], "%d:%d:%d:%d", 
  364.        &endhr, &endmin, &endsec, &endfr);
  365.     sprintf(ehr, "%.2d", endhr);
  366.     sprintf(emin, "%.2d", endmin);
  367.     sprintf(esec, "%.2d", endsec);
  368.     sprintf(eframe, "%.2d", endfr);
  369.     xv_set(vcrEdit_editPopup->editEndTxt1, PANEL_VALUE, ehr, NULL);
  370.     xv_set(vcrEdit_editPopup->editEndTxt2, PANEL_VALUE, emin, NULL);
  371.     xv_set(vcrEdit_editPopup->editEndTxt3, PANEL_VALUE, esec, NULL);
  372.     xv_set(vcrEdit_editPopup->editEndTxt4, PANEL_VALUE, eframe, NULL);
  373.     
  374.     xv_set(vcrEdit_editPopup->editLabelTxt, PANEL_VALUE, 
  375.        label[editnum], NULL);                    /* label */
  376.     xv_set(vcrEdit_editPopup->editSpeedTxt, PANEL_VALUE,
  377.        (int) speedStg[editnum], NULL);                /* speed */
  378.     switch (audioStg[editnum])                        
  379.     {
  380.      case Stereo:
  381.       strcpy(audio, "Stereo");
  382.       break;
  383.      case Right:
  384.       strcpy(audio, "Right");
  385.       break;
  386.      case Left:
  387.       strcpy(audio, "Left");
  388.       break;
  389.      case Mute:
  390.       strcpy(audio, "Mute");
  391.       break;
  392.     }
  393.     xv_set(vcrEdit_editPopup->editAudioMenuButton, 
  394.        PANEL_LABEL_STRING, audio, NULL);                /* audio */
  395.     SetDuration();                            /* duration */
  396.     sprintf(msg, "Current Selection : Edit #%d", editnum+1);
  397.     xv_set(vcrEdit_editPopup->editNewEditMsg, PANEL_VALUE, msg, NULL);    
  398.     xv_set(vcrEdit_editPopup->editModButton,                /* Make the modify, delete buttons active */
  399.        PANEL_INACTIVE, FALSE, NULL);
  400.     xv_set(vcrEdit_editPopup->editDelButton,
  401.        PANEL_INACTIVE, FALSE, NULL);
  402.     xv_set(vcrEdit_editPopup->editScrollList,
  403.        PANEL_LIST_SELECT, editnum, TRUE,
  404.        NULL); 
  405.     PlayEdit(startAddress, 0);                        /* Seek to selection first (block for completion of search) */
  406.     DevSetVideo(myVideo, 0);                        /* Video muted */
  407.   }
  408. }                                    /* end function SetSelection */
  409.  
  410.  
  411. void DevResumeSelection(int end)
  412. {    
  413.   PlayEdit(NULL, end);
  414. }
  415.  
  416.  
  417.  
  418. void PreSearch(Notify_client client, int which)
  419. {
  420.   static MAESelection select;
  421.   
  422.   notify_set_itimer_func(vcrEdit_window1->window1,            /* Switch off timer */
  423.              NOTIFY_FUNC_NULL, ITIMER_REAL, NULL, NULL);
  424.   select.start = editnum + 2;
  425.   select.offset = 0;
  426.   SetSelection(&select);                        /* Do presearch */
  427. }  
  428.  
  429.  
  430.  
  431. /* Play selection */
  432. void PerformSelection()
  433. {
  434.   int end; 
  435.   int endhr; 
  436.   int endmin; 
  437.   int endsec; 
  438.   int endfr;
  439.   int start; 
  440.   int starthr; 
  441.   int startmin; 
  442.   int startsec; 
  443.   int startfr;
  444.   static struct itimerval timer;
  445.   
  446.   if ((editnum == -1)                            /* Nothing selected or nothing in edit list or no device */
  447.       || (lines == 0)
  448.       || (myVideo == (VideoObject*)NULL))
  449.     return;
  450.   
  451.   DevSetVideo(myVideo, 1);                        /* Video mute off */
  452.   
  453.   endfr = atoi((char*) xv_get(vcrEdit_editPopup->editEndTxt4, PANEL_VALUE));
  454.   endhr = atoi((char*) xv_get(vcrEdit_editPopup->editEndTxt1, PANEL_VALUE));
  455.   endmin = atoi((char*) xv_get(vcrEdit_editPopup->editEndTxt2, PANEL_VALUE));
  456.   endsec = atoi((char*) xv_get(vcrEdit_editPopup->editEndTxt3, PANEL_VALUE));
  457.   end = ConvertToAddress(endhr, endmin, endsec, endfr);
  458.   
  459.   starthr = atoi((char*) xv_get(vcrEdit_editPopup->editStartTxt1, PANEL_VALUE));
  460.   startmin = atoi((char*) xv_get(vcrEdit_editPopup->editStartTxt2, PANEL_VALUE));
  461.   startsec = atoi((char*) xv_get(vcrEdit_editPopup->editStartTxt3, PANEL_VALUE));
  462.   startfr = atoi((char*) xv_get(vcrEdit_editPopup->editStartTxt4, PANEL_VALUE));
  463.   start = ConvertToAddress(starthr, startmin, startsec, startfr);
  464.   
  465.   PlayEdit(0, end);
  466.   if (preSearch)                            /* Is the pre-search option set? */
  467.   {                                    /* Yes, try to find the next edit */
  468.     if (editnum + 1 <= lines)                        /* Does the edit list contain an edit after this one? */
  469.     {                                    /* Yes, set a timer to queue it up after this edit... */
  470.       timer.it_value.tv_sec = (end - start) / FrameRate;        /* ...is done playing */
  471.       notify_set_itimer_func((Notify_client) vcrEdit_window1->window1, 
  472.                  (Notify_func) PreSearch, ITIMER_REAL, &timer, 
  473.                  (struct itimerval*) NULL);
  474.     }
  475.     else                                /* No, the last edit on the list was played, so... */
  476.       lastEditPlayed = Yes;                        /* ...pre-search is temporarily invalid. */
  477.   }
  478.   return;
  479. }                                    /* end function PerformSelection */
  480.  
  481.  
  482. /* Send name of edit list file to the TimeLine */
  483. char** GetDoc(void* unusedArg)
  484. {
  485.   static char* doc;
  486.   
  487.   doc = (char*) xv_get(vcrEdit_editPopup->editPopup, XV_LABEL);
  488.   if (strlen(doc) == 0 || realpath(doc, canonFilename) == NULL) 
  489.     strcpy(canonFilename, "Untitled");
  490.   else strcpy(canonFilename, realpath(doc, canonFilename));
  491.   return(&canonFilename);
  492. }                                    /* end function GetDoc */
  493.  
  494.  
  495.  
  496. /* Send selection data to TimeLine */
  497. MAESelection* GetSelection(void* unusedArg)
  498. {
  499.   static MAESelection select;
  500.   int startmin;
  501.   int starthr;
  502.   int startsec;
  503.   int startfr;
  504.   int endmin;
  505.   int endhr;
  506.   int endsec;
  507.   int endfr;
  508.   int duration;
  509.   int speedInDevice;
  510.   
  511.   if ((editnum == -1) || (!lines))
  512.   {                    
  513.     select.duration = -1;
  514.     return &select;
  515.   }
  516.   
  517.   sscanf(startframe[editnum], "%d:%d:%d:%d", &starthr, &startmin, &startsec, &startfr);
  518.   sscanf(endframe[editnum], "%d:%d:%d:%d", &endhr, &endmin, &endsec, &endfr);
  519.   
  520.   if (myVideo)
  521.     speedInDevice = (int) DevCalcSpeed(myVideo, speedStg[editnum], 1);    
  522.   else 
  523.     speedInDevice = speedStg[editnum];
  524.   
  525.   duration = (ConvertToAddress(endhr, endmin, endsec, endfr) 
  526.           - ConvertToAddress(starthr, startmin, startsec, startfr));
  527.   
  528.   if (speedInDevice)
  529.     duration = (((duration%speedInDevice)/speedInDevice > 0.5) ? 
  530.         (duration/speedInDevice) + 1 
  531.         : duration/speedInDevice);
  532.   else
  533.     duration = -1;
  534.   
  535.   select.start =  editnum + 1;
  536.   select.end = editnum + 1;
  537.   select.offset = 0;
  538.   select.duration = 1000 * duration;  
  539.   if (strlen(label[editnum]) != 0)
  540.     strcpy(select.label, label[editnum]);   
  541.   else
  542.     strcpy(select.label, "NO LABEL");
  543.   
  544.   return (&select);
  545. }                                    /* end function GetSelection */
  546.  
  547.  
  548. /* Halts playback of Selection as directed by TimeLine */
  549. void HaltSelection()
  550. {
  551.   if ((editnum != -1) && (lines != 0) && (myVideo != (VideoObject*)NULL))
  552.   {
  553.     notify_set_itimer_func((Notify_client) vcrEdit_window1->window1, /* Turn off timer */
  554.                NOTIFY_FUNC_NULL, ITIMER_REAL, NULL, NULL);
  555.     DevStop(myVideo);
  556.   }
  557.   return;
  558. }                                    /* end function HaltSelection */
  559.  
  560.  
  561. /* Pauses playback of Selection as directed by TimeLine */
  562. void PauseSelection()
  563. {
  564.   if ((editnum != -1) && (lines != 0) &&
  565.       (myVideo != (VideoObject*)NULL))
  566.   {
  567.     notify_set_itimer_func((Notify_client) vcrEdit_window1->window1, /* Turn off timer */
  568.                NOTIFY_FUNC_NULL, ITIMER_REAL,
  569.                NULL, NULL);
  570.     DevStill(myVideo);
  571.   }
  572.   return;
  573. }                                    /* end function PauseSelection */
  574.  
  575.  
  576. /* Resumes playback of Selection as directed by TimeLine */
  577. void ResumeSelection()
  578. {
  579.   int end;
  580.   int endhr;
  581.   int endmin;
  582.   int endsec;
  583.   int endfr;
  584.   
  585.   if ((editnum != -1) && lines && myVideo)
  586.   {
  587.     sscanf(endframe[editnum], "%d:%d:%d:%d", &endhr, &endmin, &endsec, &endfr);
  588.     end = ConvertToAddress(endhr, endmin, endsec, endfr);
  589.     DevResumeSelection(end);
  590.   }
  591. }                                    /* end function ResumeSelection */
  592.  
  593.  
  594. /* Iconifies application as directed by TimeLine */
  595. void HideApplication()
  596. {
  597.   xv_set(vcrEdit_window1->window1, FRAME_CLOSED, TRUE, NULL);
  598.   XFlush((Display*)xv_get(vcrEdit_window1->window1, XV_DISPLAY));
  599. }                                    /* end function HideApplication */
  600.  
  601.  
  602. /* Deiconifies application as directed by TimeLine */
  603. void ShowApplication()
  604. {
  605.   xv_set(vcrEdit_window1->window1, FRAME_CLOSED, FALSE, NULL);
  606.   xv_set(vcrEdit_window1->window1, XV_SHOW, TRUE, NULL);           
  607.   if (xv_get(vcrEdit_optionsPopup->optionsPopup, XV_SHOW) == TRUE)  /* Show all popups that were up originally */
  608.   {
  609.     xv_set(vcrEdit_optionsPopup->optionsPopup, XV_SHOW, TRUE, NULL);
  610.   }
  611.   if (xv_get(vcrEdit_previewPopup->previewPopup, XV_SHOW) == TRUE) 
  612.   {
  613.     xv_set(vcrEdit_previewPopup->previewPopup, XV_SHOW, TRUE, NULL);
  614.   }
  615.   if (xv_get(vcrEdit_editPopup->editPopup, XV_SHOW) == TRUE) 
  616.   {
  617.     xv_set(vcrEdit_editPopup->editPopup, XV_SHOW, TRUE, NULL);
  618.   }  
  619.   if (xv_get( vcrEdit_infoPopup->infoPopup, XV_SHOW) == TRUE) 
  620.   {
  621.     xv_set(vcrEdit_infoPopup->infoPopup, XV_SHOW, TRUE, NULL);
  622.   }
  623.   XFlush((Display*) xv_get(vcrEdit_window1->window1, XV_DISPLAY));    
  624.   return;
  625. }                                    /* end function ShowApplication */
  626.     
  627.  
  628. IconData* GetAppIcon()
  629. {
  630.   static IconData returnVal;
  631.   static unsigned short baseWindow_bits[] = {
  632. #include "icons/vcrEditIcon"
  633.         };
  634.   
  635.   returnVal.iconData = (char *)malloc(sizeof(baseWindow_bits));
  636.   bcopy(baseWindow_bits, returnVal.iconData, sizeof(baseWindow_bits));
  637.   if (returnVal.iconData)
  638.     returnVal.dataLength = sizeof(baseWindow_bits);
  639.   return(&returnVal);
  640. }                                    /* end function GetAppIcon */
  641.